package memorphic.ui
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.Dictionary;
	
	import memorphic.slide.IUIAction;
	
	import mx.controls.Button;
	
	public class ButtonUIActionBinder
	{
		
		private static const controlsDictionary:Dictionary = new Dictionary(true);
		
		
		
		private var action:IUIAction;
		
		public function ButtonUIActionBinder(button:Button, action:IUIAction, eventType:String=null)
		{
			if(eventType == null){
				eventType = MouseEvent.CLICK;
			}
			this.action = action;
			button.addEventListener(eventType, onUIEvent);
			if(!button.label){
				button.label = action.label;
			}
			if(!button.toolTip){
				button.toolTip = action.tooltipText;
			}
			button.enabled = action.enabled;
		}
		
		private function onUIEvent(e:Event):void
		{
			action.execute();
		}
		
		
		public static function bind(button:Button, action:IUIAction, eventType:String="click"):void
		{
			controlsDictionary[button] = new ButtonUIActionBinder(button, action, eventType);
		}

	}
}